<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <title>修改用户</title>

    <meta charset="UTF-8">

    <script src="../../../js/jquery-2.0.3.min.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.min.css">
    <script src="../../../js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrapValidator.css">
    <script src="../../../js/bootstrapValidator.js"></script>
    <script src="../../../js/jquery.cookie.js"></script>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="../../../js/hostConfig.js"></script>


</head>
<body>
<div class="container kv-main" id="app">

    <div class="jumbotron">
        <h1>修改用户</h1>
        <p></p>
    </div>

    <form name="form" action="/role/update/submit" method="post" enctype="multipart/form-data" class="form-horizontal">

        <div class="form-group">
            <label class="col-lg-1 control-label">名称</label>
            <div class="col-lg-6">
                <input type="text" id="id" name="name" class="form-control" placeholder="用户ID" v-model="user.id"
                       disabled>
            </div>
        </div>


        <div class="form-group">
            <label class="col-lg-1 control-label">名称</label>
            <div class="col-lg-6">
                <input type="text" id="name" name="name" class="form-control" placeholder="用户名称"
                       v-model="user.name">
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label">手机</label>
            <div class="col-lg-6">
                <input type="text" id="description" name="description" class="form-control" placeholder="用户手机"
                       v-model="user.mobilephone">
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label"></label>
            <div class="col-lg-4 col-lg-offset-1">
                <a class="btn btn-info btn-block" href="javascript:;" v-on:click="submitUserInfo">提交</a>
            </div>
        </div>

    </form>
</div>

</body>
</html>
<script>
    var path = host_tomcatR;
    var app = new Vue({
        el: '#app',
        data: {
            id: "",
            password: "",
            user: [],
            ret: []
        },
        methods: {
            submitUserInfo: function () {
                $.ajax({
                    type: "post",
                    url: path + "/user/update",
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain: true,
                    data: {
                        id: this.id,
                        mobilephone: this.user.mobilephone,
                        name: this.user.name
                    },
                    success: function (data) {
                        if (data["code"] == "0000") {
                            window.location.href = "/pages/manage/user/list.html"
                        } else {
                            alert(response.data.description);
                            console.log(response.data);
                        }
                    },
                    error: function (xhr, type) {
                        console.log(xhr);
                    }
                });
            },
            getUrlParam: function (key) {
                var reg = new RegExp(key + '=([^&]*)');
                var results = location.href.match(reg);
                return results ? results[1] : null;
            }
        },
        mounted() {
            this.id = this.$options.methods.getUrlParam('id');
//            $.ajax({
//                type: "post",
//                url: path + "/user/queryUserById",
//                xhrFields: {
//                    withCredentials: true
//                },
//                crossDomain: true,
//                data: {
//                    id: this.id
//                },
//                success: function (data) {
//                    console.log(data);
//                }
//            });

            axios({
                method: 'post',
                url: path + '/user/queryUserById?id=' + this.id,
                withCredentials: true
            }).then(response => this.user = response.data);

        }
    });

</script>